<?php

class Admin_Model_Kiemtracauhoi {
	
	private $testQuestion;
	
	public function __construct(){
		$this->testQuestion = new Admin_Model_DbTable_Kiemtracauhois();
		 
	}
	
	public function listTestQuestion($where=null, $orderOrRand='kc.idCauHoi DESC'){
		$dbApdater = Zend_Db_Table::getDefaultAdapter();
		$dbSelect = new Zend_Db_Select($dbApdater);
		
		$dbSelect->from(array('kc'	=> 'kiemtra-cauhoi'),'idCauHoi')
				->joinInner('cauhoi','cauhoi.idCauHoi = kc.idCauHoi',
				 	array('tenCauHoi','idMonHoc','a','b','c','d','e','dapAnDung','mucDo','trash')
				 )
				->joinInner(array('kt'=>'kiemtra'),'kt.idKiemTra = kc.idKiemTra','*'
					//array('ten','thoiGian','soCauHoi','dateStart','hourStart','dateEnd','hourEnd','username','status')	
				);
				
		if($where !=null) $dbSelect->where($where);
		$dbSelect->order($orderOrRand);
				
		return $dbSelect; 
	}
	
	public function addTestQuestion($idQuestion, $idExame){
		$data = array(
			'idCauHoi'	=>	$idQuestion,
			'idKiemTra'	=>	$idExame
		);
		$this->testQuestion->insert($data);
	}
	
	public function updateTestQuestion($idQuestion,$idExame){
		$data = array(
			'idCauHoi'	=>	$idQuestion
		);
		
		$this->testQuestion->update($data,'idKiemTra ='.$idExame);
	}
	
	public function deleteTestQuestion($idExame){
		$this->testQuestion->delete('idKiemTra ='.$idExame );
	} 
	
	public function deleteRowQuestion($idQuestion,$idExame){
		$this->testQuestion->delete('idCauHoi = '.$idQuestion.'  and idKiemTra = '.$idExame);
	}
	
	public function update($data,$where){
		$this->testQuestion->update($data, $where);
	}
	
	
}